package com.team20.map_demo.service;

import com.team20.map_demo.domain.Street;
import com.team20.map_demo.domain.StreetExample;
import com.team20.map_demo.mapper.StreetMapper;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class StreetServiceImpl implements StreetService{
    @Autowired
    private StreetMapper streetMapper;
    @Override
    public List<Street> listStreet() {
        return streetMapper.selectByExample(new StreetExample());
    }

    @Override
    public int deleteStreetByPrimaryKey(String street_Id) {
        return streetMapper.deleteByPrimaryKey(street_Id);
    }

    @Override
    public Street findStreetByPrimaryKey(String street_Id) {
        return streetMapper.selectByPrimaryKey(street_Id);
    }

    @Override
    public int savaStreet(Street street) {
        if (StringUtils.isNotBlank(street.getId())){
            return streetMapper.updateByPrimaryKey(street);
        }else{
            return streetMapper.insert(street);
        }

    }

    @Override
    public List<Street> selectStreetTypeCount(String street_Name) {
        return streetMapper.selectStreetTypeCount(street_Name);
    }

    @Override
    public List<Street> findStreetByName() {
        return streetMapper.selectAllStreet();
    }
}
